package com.caisejingyu.whales.common.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;

/**
 * SharedPreferenceUtil
 *
 */
@SuppressWarnings({"WeakerAccess", "unused"})
public final class SharedPreferenceUtil {

    private SharedPreferenceUtil() {}

    public static SharedPreferences getSharePreferences(@NonNull Context context, @NonNull String name) {
        return context.getSharedPreferences(name, Context.MODE_PRIVATE);
    }

    public static boolean getBoolean(@NonNull SharedPreferences sp, @NonNull String key, boolean defaultValue) {
        return sp.getBoolean(key, defaultValue);
    }

    public static void putBoolean(@NonNull SharedPreferences sp, @NonNull String key, boolean value) {
        sp.edit().putBoolean(key, value).apply();
    }

    public static String getString(@NonNull SharedPreferences sp, @NonNull String key, String defaultValue) {
        return sp.getString(key, defaultValue);
    }

    public static void putString(@NonNull SharedPreferences sp, @NonNull String key, String value) {
        sp.edit().putString(key, value).apply();
    }

    public static int getInt(@NonNull SharedPreferences sp, @NonNull String key, int defaultValue) {
        return sp.getInt(key, defaultValue);
    }

    public static void putInt(@NonNull SharedPreferences sp, @NonNull String key, int value) {
        sp.edit().putInt(key, value).apply();
    }

    public static long getLong(@NonNull SharedPreferences sp, @NonNull String key, long defaultValue) {
        return sp.getLong(key, defaultValue);
    }

    public static void putLong(@NonNull SharedPreferences sp, @NonNull String key, Long value) {
        sp.edit().putLong(key, value).apply();
    }

    public static float getFloat(@NonNull SharedPreferences sp, @NonNull String key, float defaultValue) {
        return sp.getFloat(key, defaultValue);
    }

    public static void putFloat(@NonNull SharedPreferences sp, @NonNull String key, float value) {
        sp.edit().putFloat(key, value).apply();
    }

    public static void removeKey(@NonNull SharedPreferences sp, @NonNull String key) {
        sp.edit().remove(key).apply();
    }

    public static void clear(@NonNull SharedPreferences sp) {
        sp.edit().clear().apply();
    }

}
